<template>
    <view class="content">
        <u-navbar
            placeholder
            autoBack
            :autoBack="true"

            leftIcon="arrow-leftward"


        >
            <view slot="center" style="flex-grow: 1;margin-left: 80rpx">
                <u-search  @click="go" placeholder="搜索" actionText="取消" @change="change" @search="change" @custom="custom"  v-model="keyword"></u-search>
            </view>

        </u-navbar>
        <Collapse @finishDropClicks="changesaixuan"/>
        <listBox :list="goodslist"/>

    </view>
</template>
<script>
import Collapse from '@/components/Collapse'
import listBox from "@/pages/components/list-box.vue";
export default {
    name: 'index',
    components: {
        listBox,
        Collapse
    },
    data() {
        return {
            keyword:'',
			total: 0,
			goodslist: [],
			page: 1,
			zonghe: 0,
			xiaoliang: 0,
			price: 0,
			tuijian: 0,
			cid: 0,
			new: 0,
        }
    },
	onLoad(e){
		if(e.keyword){
			this.keyword = e.keyword
		}
		if(e.cid){
			this.cid = e.cid
		}
		if(e.tuijian){
			this.tuijian = 1
		}
	},
	onShow() {
		this.page = 1
		this.getlist()
	},
	onReachBottom() {
	  if (this.total > this.page) {
	    this.page++;
	    this.getlist();
	  }
	},
    methods: {
		change(e){
			console.log(e)
			this.getlist()
		},
		changesaixuan(e) {
			console.log(111111111111111111)
		  this.zonghe = e[0] ? e[0] : 0;
		  this.new = e[1] ? e[1] : 0;
		  this.price = e[2] ? e[2] : 0;
		  this.xiaoliang = e[3] ? e[3] : 0;
		  this.page = 1;
		  this.getlist();
		},
		getlist() {
		  var that = this;
		  this.$.ajax(
		    1,
		    "POST",
		    "index/getgoodslist",
		    {
		      page: this.page,
		      zonghe: this.zonghe,
		      new: this.new,
		      price: this.price,
		      tuijian: this.tuijian,
		      cid: this.cid,
		      xiaoliang: this.xiaoliang,
			  keyword:this.keyword
		    },
		    (res) => {
		      if (res.code == 1) {
		        console.log(res.data.list);
		        if (that.page == 1) {
		          that.goodslist = [];
		        }
		        that.goodslist = [...res.data.list, ...that.goodslist];
		      }
		    }
		  );
		},
        custom(){
            uni.navigateBack()
        },
        go(){
			uni.navigateBack()
        },
        fichangenishDropClicks(e){

            this.$emit('changesaixuan', e)
        }
    },
    created() {

    },
    mounted() {

    },
}
</script>
<style lang="scss" scoped>

.content{
  position: absolute;
  width: 100%;
  padding:20rpx 20rpx;
  height: 100%;
  font-size: 28rpx;
  background-color: #fff;

}
</style>

